package com.winspread.app.ui

import android.util.Log
import android.widget.EditText
import androidx.lifecycle.Observer
import com.winspread.active.extension.loge
import com.winspread.mvvm.base.vm.BaseNotVmActivity
import com.winspread.ui.R
import com.winspread.ui.databinding.ActivityDialogBinding
import com.winspread.ui.dialog.BaseDialog
import com.winspread.app.flow.EventBean
import com.winspread.mvvm.flowbus.SharedFlowBus

/**
 *Author: Amin
 *Data: 2021/9/28 14:43
 *
 *Description:
 *
 */
class DialogActivity : BaseNotVmActivity<ActivityDialogBinding>(R.layout.activity_dialog) {


    override fun initView() {
        binding.tvDialogDelete.setOnClickListener {
            BaseDialog()
                .setFragmentManager(supportFragmentManager)
                .setMessage("确定删除?")
                .setAnimStyle(R.style.dialogAnim)
                .setCanceledOnTouchOutside(true) // 点击dialog外部关闭dialog
                .setDismissMethod { // Dialog消失回调
                    Log.e("TAG", "initView: setDismissMethod")
                }
                .setPositiveButtonMethod { dialog, view -> // 点击底部右侧按钮回调
                    Log.e("TAG", "initView: setPositiveButtonMethod")
                    dialog?.dismiss()
                }.show()
        }

        binding.tvDialogCustom.setOnClickListener {

            BaseDialog()
                .setFragmentManager(supportFragmentManager)
                .setTitle("添加xx")
                .setDialogView(R.layout.dialog_xx)
//                .setWindowSize(900, 600)
                .setBuildMethod { _, view -> // DialogFragment onCreateView方法时回调
                    view?.run {
                        //flowBus 
                        SharedFlowBus.onSticky(EventBean::class.java).observe(this@DialogActivity, Observer {
                            findViewById<EditText>(R.id.xx_edit).setText(it.value)
                        })



                    }
                }
                .setNegativeToDismiss(false) // 取消点击底部左侧按钮自动关闭dialog
                .setNegativeButtonMethod { dialog, view -> // 点击底部左侧按钮回调
                    dialog?.dismiss()
                }
                .setPositiveButtonMethod{ dialog, view ->
                "${view?.findViewById<EditText>(R.id.xx_edit)?.text}".loge()

                }
                .show()
        }

        binding.tvDialogSim.setOnClickListener {
            BaseDialog()
                .setFragmentManager(supportFragmentManager)
                .setTitle("提示")
                .setMessage("提示dialog提示dialog提示dialog")
                .setLeftTitle(true)
                .setVisibilityBtnDialogCancel(true)
                .setPositiveButtonMethod { dialog, view ->
                    dialog?.dismiss()
                    Log.e("TAG", "initView: setPositiveButtonMethod")
                }.show()
        }



    }
}